package com.example.demo.api;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ApiIntercept implements HandlerInterceptor {
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// 执行完毕，返回前拦截
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// 在处理过程中，执行拦截
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		/*
		 * System.out.println("请求地址:"+request.getRequestURI());
		 * 
		 * String token = request.getHeader("sign"); System.out.println("请求头:"+token);
		 * 
		 * String timeStamp = request.getHeader("timeStamp"); String currTimesub =
		 * TimeUtil.currTimesub(1);
		 * 
		 * if(token!=null){
		 * 
		 * Map<String, String> map = APIUtil.toMap(request); boolean sts =
		 * APIUtil.pwd(token, map); if(!sts){
		 * response.sendRedirect(request.getContextPath()+"/api/errorToken"); return
		 * false; } return true; }else{
		 * response.sendRedirect(request.getContextPath()+"/api/errorToken"); return
		 * false; }
		 */

		return true;

	}
}
